<template>
  <div class="bottom-left-chart-1">
    <div class="header-name">登录（DAU）</div>
    <div class="details-value"><span>{{ dau }}</span></div>
    <dv-charts :option="option" />
  </div>
</template>
<script>
import { daudata, installdata } from '@/api/chart'
export default {
  name: 'BottomLeftChart1',
  data() {
    return {
      option: {},
      dau: 0,
      install: 0
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      daudata().then(response => {
        this.handleDauData(response.data)
        installdata().then(response => {
          this.handleInstallData(response.data)
        })
      })
    },
    handleDauData(data) {
      data.forEach(item => {
        this.dau += parseInt(item.dau_count)
      })
    },
    handleInstallData(data) {
      data.forEach(item => {
        this.install += parseInt(item.inst_count)
      })
      this.setOpt(this.install, this.dau)
    },
    setOpt(install, dau) {
      const old = parseInt(dau) - parseInt(install)
      this.option = {
        series: [
          {
            type: 'pie',
            data: [
              { name: '新玩家', value: install, radius: ['30%', '33%'] },
              { name: '老玩家', value: old, radius: ['32%', '35%'] }
            ],
            outsideLabel: {
              labelLineEndLength: 20,
              formatter: '{percent}%\n{name}',
              style: {
                fill: '#fff'
              }
            }
          },
          {
            name: 'decoration ring',
            type: 'pie',
            data: [
              { value: 10, radius: ['50%', '53%'] }
            ],
            outsideLabel: {
              show: false
            },
            pieStyle: {
              fill: 'rgba(255, 255, 255, 0.2)'
            }
          },
          {
            name: 'decoration ring',
            type: 'pie',
            data: [
              { value: 10, radius: ['45%', '46%'] }
            ],
            outsideLabel: {
              show: false
            },
            pieStyle: {
              fill: 'rgba(255, 255, 255, 0.2)'
            }
          }
        ],
        color: ['#00c0ff', '#3de7c9', '#fff', '#00c0ff', '#3de7c9', '#fff'],
        height: 200
      }
    }
  }
}
</script>

<style lang="scss">
.bottom-left-chart-1 {
  position: relative;

  .header-name {
    height: 100px;
    line-height: 100px;
    font-size: 20px;
    text-align: center;
  }

  .details-value {
    height: 40px;
    font-size: 30px;
    font-weight: bold;
    text-align: center;

    span {
      color: #00c0ff;
      font-size: 45px;
    }
  }

  .dv-charts-container {
    height: 100%;
  }

  .decoration-ring {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 5px solid fade(#fefefe, 30);
    top: 190px;
    left: 50%;
    transform: translateX(-50%);
  }
}
</style>
